package com.example.dao.impl;

import com.example.common.R;
import com.example.dao.ChannelDao;
import com.example.pojo.entity.WmChannel;
import com.example.utils.JDBCUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 * 获取频道列表
 */
public class ChannelDaoImpl implements ChannelDao {
    @Override
    public R getChannelList() throws Exception {
        Connection connection = JDBCUtil.connection();
        String sql1 = "select * from wm_channel";
        PreparedStatement ps = connection.prepareStatement(sql1);
        ResultSet resultSet = ps.executeQuery();
        List<WmChannel> channelList = new ArrayList<>();
        while (resultSet.next()) {
            WmChannel channel = new WmChannel();
            //获取数据
            channel.setId(resultSet.getInt("id"));
            channel.setChannelName(resultSet.getString("channel_name"));
            channelList.add(channel);
        }
        JDBCUtil.closeConn(ps,connection);

        return R.ok(channelList);
    }
}
